﻿using Domain.Entity;
using DtoFw;
using DtoFw.Query;
using Repository.Base;
using System;
using System.Collections.Generic;
using System.Text;
using Util;

namespace Repository
{
    public class MainDicRepository : BaseRepository<MainDicEntity>
    {
        private readonly SnowFlakeGenerator worker;
        public MainDicRepository(SnowFlakeGenerator snowFlakeGenerator) : base(snowFlakeGenerator)
        {
            this.worker = snowFlakeGenerator;
        }

        /// <summary>
        /// 父字典
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public Pager<MainDicEntity> GetPagerList(DicQueryDto query)
        {
            return base.GetPager(query, linq =>
            {
                if (query.ParentId > 0)
                    linq = linq.Where(t => t.ParentId == query.ParentId);
                else
                    linq = linq.Where(t => t.ParentId < 1);
                if (!string.IsNullOrWhiteSpace(query.DicName))
                    linq = linq.Where(t => t.Name.Contains(query.DicName));
                if (!string.IsNullOrWhiteSpace(query.DicCode))
                    linq = linq.Where(t => t.Code == query.DicCode);
                return linq;
            });
        }
    }
}
